package io.terminus.paas.profiler.restful

import io.terminus.paas.profiler.common.BaseController
import io.terminus.paas.profiler.model.Consumer
import io.terminus.paas.profiler.service.ConsumerService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController

/**
 * Created by gengrong on 16/5/16.
 */
@RestController
@RequestMapping("/api/consumers/{consumerId}")
class Consumers @Autowired constructor(
        private val consumerService: ConsumerService
) : BaseController() {

    @RequestMapping(method = arrayOf(RequestMethod.GET))
    fun desc(@PathVariable consumerId: Long): Consumer {
        return consumerService.getDetailByConsumerId(getRegistryAddress(), consumerId)
    }

    @RequestMapping("/enable", method = arrayOf(RequestMethod.POST))
    fun enable(@PathVariable consumerId: Long) {
        return consumerService.enableConsumer(getRegistryAddress(), consumerId)
    }

    @RequestMapping("/disable", method = arrayOf(RequestMethod.POST))
    fun disable(@PathVariable consumerId: Long) {
        return consumerService.disableConsumer(getRegistryAddress(), consumerId)
    }
}